﻿using System;
using System.Collections.Generic;
using HR60_PanelSoft.Model.BaseModel;

namespace HR60_PanelSoft.Model
{
	/// <summary>
	/// 设备对象
	/// </summary>
	public class Device : RefModel
	{
		/// <summary>
		/// 昵称
		/// </summary>
		public string nickName = "";

		/// <summary>
		/// 设备类型
		/// </summary>
		public DeviceType type = null;

		/// <summary>
		/// 设备品牌
		/// </summary>
		public DeviceBrand brand = null;

		/// <summary>
		/// 子设备列表
		/// </summary>
		public List<Device> childDevices = new List<Device>();

		/// <summary>
		/// 已连接的线路列表,ref
		/// </summary>
		public List<string> connectedPins = new List<string>();

		/// <summary>
		/// 已连接的线路列表, ref to object
		/// </summary>
		/// <returns>The connnected pins.</returns>
		public List<Pin> getConnnectedPins()
		{
			List<Pin> list = new List<Pin> ();
			foreach (string uuid in connectedPins)
			{
				list.Add (Pin.find (uuid));
			}
			return list;
		}

		// find by uuid
		public static Device find(string uuid)
		{
			foreach (DeviceGroup group in Proj.currentProj.deviceGroups) 
			{
				foreach (Device device in group.devices)
				{
					if (device.uuid == uuid)
						return device;
					if (device.childDevices == null)
						continue;
					foreach (Device sub in device.childDevices)
					{
						if (sub.uuid == uuid)
							return sub;
					}
				}
			}
			return null;
		}
	}
}
